const Mock = require('mockjs')

const List = []
const count = 100

const baseContent = '<p>I am testing data, I am testing data.</p><p><img src="https://wpimg.wallstcn.com/4c69009c-0fd4-4153-b112-6cb53d1cf943"></p>'
const image_uri = 'https://wpimg.wallstcn.com/e4558086-631c-425c-9430-56ffb46e70b3'

for (let i = 0; i < count; i++) {
  List.push(Mock.mock({
    category: "@integer(0, 3)",
    video: '@integer(1, 3)',
    poster: '@first',
    price: '@float(0, 100, 2, 2)',
    id: '@increment',
    timestamp: +Mock.Random.date('T'),
    author: '@first',
    reviewer: '@first',
    title: '@title(5, 10)',
    content_short: 'mock data',
    content: baseContent,
    forecast: '@float(0, 100, 2, 2)',
    importance: '@integer(1, 3)',
    'type|1': ['CN', 'US', 'JP', 'EU'],
    'status|1': ['published', 'draft'],
    display_time: '@datetime',
    comment_disabled: true,
    pageviews: '@integer(300, 5000)',
    image_uri,
    platforms: ['a-platform']
  }))
}

module.exports = [{
  url: "/get/domtree",
  type: "get",
  response: () => {
    let data = {
      type: 'doc',
      content: [{
          type: 'text',
          content: [{
            styles: {
              fontSize: '28px',
              color: '#333',
              lineHeight: 2.5,
              textAlign: 'center'
            },
            type: 'text',
            textNode: "h1",
            text: "本项目文档 @integer(300, 5000)"
          }]
        }, {
          type: 'text',
          content: [{
            styles: {
              fontSize: '22px',
              color: '#333',
              lineHeight: 1.5,
              textAlign: 'center'
            },
            type: 'text',
            textNode: "h2",
            text: "技术栈：<span style='color:#e51937;'>vue3</span>、<span style='color:#e51937;'>element-plus</span>"
          }]
        }, {
          type: 'paragraph',
          content: [{
              type: 'text',
              textNode: "div",
              styles: {
                marginTop: '20px'
              },
              text: "本项目使用vue3<i style='color:#42e15c'> composition-api </i>书写 @integer(300, 5000)"
            }, {
              type: 'text',
              textNode: "p",
              styles: {
                color: 'blue',
                lineHeight: 2
              },
              text: "采用<em style='color:#42e15c'> jsx </em>进行组件开发 @integer(300, 5000)"
            },
            {
              type: 'text',
              textNode: "p",
              text: "使用<em style='color:#42e15c'> mockjs </em>模拟接口 @integer(300, 5000)"
            }
          ]
        },
        {
          type: "table",
          props: {
            size: "mini",
            headerRowStyle: {
              color: "#333",
            },
            headerCellStyle: {
              backgroundColor: "#ddd",
            }
          },
          content: [{
              type: 'row',
              content: [{
                type: "cell",
                content: [{
                  type: "text",
                  prop: 'name',
                  label: '姓名',
                  text: "@first"
                }]
              }, {
                type: "cell",
                content: [{
                  type: "text",
                  prop: 'age',
                  label: '年龄',
                  text: "@integer(2, 120)"
                }]
              }, {
                type: "cell",
                content: [{
                  type: "text",
                  prop: 'job',
                  label: '职业',
                  'text|1': ['开发', '测试', '运维', '实施', '教师'],
                }]
              }, {
                type: "cell",
                content: [{
                  type: "text",
                  prop: 'address',
                  label: '地址',
                  props: {
                    showOverflowTooltip: true
                  },
                  styles: {
                    textAlign: "center",
                  },
                  text: '@title(5, 10)'
                }]
              }]
            },
            {
              type: 'row',
              content: [{
                type: "cell",
                content: [{
                  type: "text",
                  prop: 'name',
                  label: '姓名',
                  text: "@first"
                }]
              }, {
                type: "cell",
                content: [{
                  type: "text",
                  prop: 'age',
                  label: '年龄',
                  text: "@integer(2, 120)"
                }]
              }, {
                type: "cell",
                content: [{
                  type: "text",
                  prop: 'job',
                  label: '职业',
                  'text|1': ['开发', '测试', '运维', '实施', '教师'],
                }]
              }, {
                type: "cell",
                content: [{
                  type: "text",
                  prop: 'address',
                  label: '地址',
                  props: {
                    showOverflowTooltip: true
                  },
                  styles: {
                    textAlign: "center",
                  },
                  text: '@title(5, 10)'
                }]
              }]
            },
            {
              type: 'row',
              content: [{
                type: "cell",
                content: [{
                  type: "text",
                  prop: 'name',
                  label: '姓名',
                  text: "@first"
                }]
              }, {
                type: "cell",
                content: [{
                  type: "text",
                  prop: 'age',
                  label: '年龄',
                  text: "@integer(2, 120)"
                }]
              }, {
                type: "cell",
                content: [{
                  type: "text",
                  prop: 'job',
                  label: '职业',
                  'text|1': ['开发', '测试', '运维', '实施', '教师'],
                }]
              }, {
                type: "cell",
                content: [{
                  type: "text",
                  prop: 'address',
                  label: '地址',
                  props: {
                    showOverflowTooltip: true
                  },
                  styles: {
                    textAlign: "center",
                  },
                  text: '@title(5, 10)'
                }]
              }]
            },
            {
              type: 'row',
              content: [{
                type: "cell",
                content: [{
                  type: "text",
                  prop: 'name',
                  label: '姓名',
                  text: "@first"
                }]
              }, {
                type: "cell",
                content: [{
                  type: "text",
                  prop: 'age',
                  label: '年龄',
                  text: "@integer(2, 120)"
                }]
              }, {
                type: "cell",
                content: [{
                  type: "text",
                  prop: 'job',
                  label: '职业',
                  'text|1': ['开发', '测试', '运维', '实施', '教师'],
                }]
              }, {
                type: "cell",
                content: [{
                  type: "text",
                  prop: 'address',
                  label: '地址',
                  props: {
                    showOverflowTooltip: true
                  },
                  styles: {
                    textAlign: "center",
                  },
                  text: '@title(5, 10)'
                }]
              }]
            }, {
              type: 'row',
              content: [{
                type: "cell",
                content: [{
                  type: "text",
                  prop: 'name',
                  label: '姓名',
                  text: "@first"
                }]
              }, {
                type: "cell",
                content: [{
                  type: "text",
                  prop: 'age',
                  label: '年龄',
                  text: "@integer(2, 120)"
                }]
              }, {
                type: "cell",
                content: [{
                  type: "text",
                  prop: 'job',
                  label: '职业',
                  'text|1': ['开发', '测试', '运维', '实施', '教师'],
                }]
              }, {
                type: "cell",
                content: [{
                  type: "text",
                  prop: 'address',
                  label: '地址',
                  props: {
                    showOverflowTooltip: true
                  },
                  styles: {
                    textAlign: "center",
                  },
                  text: '@title(5, 10)'
                }]
              }]
            }

          ]
        },
        {
          type: 'text',
          content: [{
            styles: {
              fontSize: '16px',
              color: 'red'
            },
            type: 'text',
            textNode: "span",
            text: "我是文本 Hello, Word! @integer(300, 5000)"
          }]
        }, {
          type: 'paragraph',
          content: [{
            styles: {
              fontSize: '14px',
              color: '#666',
              lineHeight: 1.5,
              textAlign: 'right'
            },
            type: 'text',
            textNode: "p",
            text: "本文样式均由接口返回样式决定"
          }]
        }, {
          type: 'paragraph',
          content: [{
            styles: {
              fontSize: '14px',
              color: '#666',
              lineHeight: 1.5,
              textAlign: 'right'
            },
            type: 'text',
            textNode: "p",
            text: "@DATETIME('yyyy-MM-dd HH:mm:ss')"
          }]
        }
      ]
    };
    return {
      code: 200,
      data
    }
  }
}, {
  url: "/lesson/list",
  type: "get",
  response: config => {
    const {
      category,
      pageSize = 10,
      pageIndex = 1
    } = config.query;
    let mockList = category == 0 ? List : List.filter(item => category && category == item.category)
    let pageList = List.filter((item, index) => index < pageSize * pageIndex && index >= pageSize * (pageIndex - 1))

    return {
      code: 200,
      data: {
        pageSize: pageSize,
        pageIndex: pageIndex,
        totalCount: mockList.length,
        totalPage: Math.ceil(mockList.length / pageSize),
        list: category == 0 ? List : pageList
      }
    }
  }
}]